<extend name="Public:index" />
<block name="main-crumb">
	<li class="active">菜单列表</li>
</block>
<block name="main-content">
	<div class="container-fluid">
		<div class="row">
			<div class="col-12">
				<div class="card">
					<div class="card-body">
						<h4 class="header smaller lighter blue definewidth m10">{$fmenu}</h4>
						<table id="sort" class="table table-bordered table-hover definewidth m10">
							<thead>
								<tr>
									<th>编号</th>
									<th>序号</th>
									<th>栏目名称</th>
									<th>链接地址</th>
									<th>操作时间</th>
									<th>管理操作</th>
								</tr>
							</thead>
							<tbody>
								<volist name="rolerows" id="mlist">
									<tr>

										<td>{$mlist[menuid]}</td>
										<td class="index" data-id="{$mlist.menuid}">{$mlist.sorts}</td>
										<td>{$mlist[menuname]}</td>
										<td>{$mlist[url]}</td>
										<td>{$mlist[updatetimes]}</td>
										<td>
											<a href="__APP__/web/menu/add?id={$mlist[menuid]}&fmenu={$mlist[menuname]}">添加子菜单</a>&nbsp;&nbsp;
											|&nbsp;&nbsp;
											<if condition="$mlist[counts] eq 0">
												<span style="color:#cccccc">子菜单</span>
												<else />
												<a href="__APP__/web/menu/index?id={$mlist[menuid]}&fmenu={$mlist[menuname]}">子菜单</a>
											</if>
											&nbsp;&nbsp;
											|&nbsp;&nbsp;<a href="__APP__/web/menu/edit?id={$mlist[menuid]}">编辑</a>&nbsp;&nbsp;
											|&nbsp;&nbsp;
											<a href="javascript:if(confirm('确认删除？'))location='__APP__/web/menu/deletes?id={$mlist[menuid]}'">删除</a>

										</td>
									</tr>
								</volist>
							</tbody>
						</table>
						<div class="row-fluid definewidth">{$page}</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</block>
<block name="myscript">
	<script>
		$(function () {
			//表格排序
			var fixHelperModified = function (e, tr) {
				var $originals = tr.children();
				var $helper = tr.clone();
				$helper.children().each(function (index) {
					$(this).width($originals.eq(index).width())
				});
				return $helper;
			},
				updateIndex = function (e, ui) {
					var data = [];
					$('td.index', ui.item.parent()).each(function (i) {
						$(this).html(i + 1);
						obj = {};
						obj.id = $(this).data('id');
						obj.sort = i + 1;
						data.push(obj);
					});
					var url = "{:U('saveSort')}";
					$.post(url, { data: data }, function (res) {
						if (res == '1') {
							notify('排序保存成功！');
							$('#configModal').modal('hide')
						} else {
							notify('排序保存失败！');
						}
					});
				};

			$("#sort tbody").sortable({
				helper: fixHelperModified,
				stop: updateIndex,
				placeholder: "widget-placeholder",
			}).disableSelection();
		});
	</script>
</block>